<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>[|.siteName|]</title>
    [|if .zTree|]
    <link rel="stylesheet" href="/static/zTree3/css/demo.css?t=5" type="text/css">
    <link rel="stylesheet" href="/static/zTree3/css/zTreeStyle/zTreeStyle.css" type="text/css"> [|end|]
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/main.css">
    <script src="/static/layui/layui.js?s=36"></script>
    <script src="/static/js/main.js?s=2124"></script>
</head>


<form>
    <div class="layui-input-inline">
        <div class="layui-inline">
            &nbsp&nbsp&nbsp&nbsp
            <select name="selectUserID" id="selectUserID" size="1" style="width: 100px;height: 37px" lay-verify="">
			   <option value="1" selected="">玩家推广号</option>
               <option value="2">userID</option>
            </select>
            <div class="layui-input-inline" style="width:150px">
                <input type="text" name="userID" id="userID" lay-verify="required|number" autocomplete="off" class="layui-input" value="">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">赠送类型:</label>
            <select name="selectGiveType" id="selectGiveType" size="1" style="width: 80px;height: 35px" lay-verify="">
                <option value="0" selected="">所有</option>
                <option value="1">赠送者</option>
                <option value="2">接收者</option>
            </select>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">时间范围:</label>
            <div class="layui-input-inline" style="width:180px;">
                <input type="text" name="date1" id="date1" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input" value="">

            </div>
            <label>-</label>
            <div class="layui-input-inline" style="width:180px;">
                <input type="text" name="date2" id="date2" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input" value="">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态:</label>
            <select name="selectGetType" id="selectGetType" size="1" style="width: 80px;height: 35px" lay-verify="">
                       <option value="0" selected="">所有</option>
                       <option value="1">已领取</option>
                       <option value="2">未领取</option>
                       <option value="3">已退回</option>
                    </select>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="queryBtn">开始查询</button>
        </div>

    </div>

</form>
<div class="layui-form">
    <table class="layui-table" lay-data="{width: 'full-10', height: 'full-105', url:'', page:true, id:'idTest'}" lay-filter="dataTable" id="dataTable">
        <thead>
            <tr>
                <th lay-data="{field:'userid', width:200, fixed: true}">推广号</th>
                <th lay-data="{field:'nickname', width:200}">昵称</th>
                <th lay-data="{field:'admin', width:200}">管理员</th>
                <th lay-data="{field:'time', width:200}">时间</th>
                <th lay-data="{field:'amount', width:200}">金币数</th>
                <th lay-data="{field:'explain', width:20000}">说明</th>
            </tr>
        </thead>
        <!-- <tbody>
            <tr>
                <td>123456</td>
                <td>妈蛋</td>
                <td>admin</td>
                <td>2017年11月6日18:06:33</td>
                <td>100000</td>
                <td>测试用的 说明个锤子</td>
            </tr>
            </tbody> -->
    </table>
</div>

<script type="text/html" id="stateTpl">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="backbtn">退回</a>
</script>



<script>
    layui.use(['table', 'form', 'layedit', 'laydate', 'jquery', 'element'], function() {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;
        $ = layui.jquery
        var element = layui.element;
        table = layui.table;

        ShowUserDatas();
        //var table = layui.table;
        //填写默认时间
        Date.prototype.Format = function(fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份 
                "d+": this.getDate(), //日 
                "h+": this.getHours(), //小时 
                "m+": this.getMinutes(), //分 
                "s+": this.getSeconds(), //秒 
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
                "S": this.getMilliseconds() //毫秒 
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }

        var date = new Date();
        var time1 = Date.parse(new Date()) / 1000; //获取当前秒数()
        var time2 = 24 * 3600 + time1;

        var unixTimestamp = new Date(time1 * 1000).Format("yyyy-MM-dd");

        document.getElementById('date1').value = unixTimestamp + " 00:00:00"

        var unixTimestamp = new Date(time2 * 1000).Format("yyyy-MM-dd");

        document.getElementById('date2').value = unixTimestamp + " 00:00:00"

        //日期
        laydate.render({
            elem: '#date1',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss'
        });

        laydate.render({
            elem: '#date2',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss'
        });

        //监听工具条
        table.on('tool(dataTable)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent == 'backbtn') { //查看
                obj.update({
                    // operation: "15"

                });

                //alert(JSON.stringify(data))


                if (data.operation != 0) {
                    layer.msg('只有未领取的才能退回', {
                        time: 3000, //20s后自动关闭
                        title: '提示信息',
                        btn: ['知道了']
                    });
                } else {
                    //
                    var jsdata = {
                        'userID': data.useridgive,
                        'giftID': data.giftId,
                        'gold': data.amount
                    }

                    $.post('[|urlfor "UserGivegiftController.GiftReturn"|]', jsdata, function(out) {
                        if (out.status == 0) {
                            layer.msg("操作成功", {
                                icon: 1
                            }, function() {
                                window.location.reload()
                            })
                        } else {
                            layer.msg(out.message)
                        }
                    }, "json");



                    return false;
                    //-----------------
                }

            }


        });


        //监听提交
        form.on('submit(queryBtn)', function(data) {
            btnClick()
            return false;
        });

        //自定义验证规则
        form.verify({
            date1: function(value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            content: function(value) {
                layedit.sync(editIndex);
            },
            user: function(value) {
                if (value.length < 5) {
                    return "请选择用户"
                }
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });


        $('#selectGetType').change(function() {
            var opt = $("#selectGetType").val();
            //alert(opt)
            //$("#queryBtn").trigger("submit");
            btnClick();
        });

        btnClick()

    });

    function btnClick() {
        var userID = document.getElementById("userID")
        var selectGiveType = document.getElementById("selectGiveType")
        var date1 = document.getElementById("date1")
        var date2 = document.getElementById("date2")
        var selectGetType = document.getElementById("selectGetType")
        localStorage["gameid"] = userID.value;    
        table.render({
            elem: '#dataTable',
            //data: datas,
            where: {

                userID: userID.value,
                selectGiveType: selectGiveType.value,
                date1: date1.value,
                date2: date2.value,
                selectGetType: selectGetType.value
            },
            url: '/usergivegift/table',
            done: function(res, curr, count) {


            },

            cols: [
                [ //标题栏
                    {
                        field: 'useridgive',
                        title: '赠送者推广号',
                        height: 300,
                        width: 150
                    }, {
                        field: 'nicknamegive',
                        title: '赠送者昵称',
                        height: 300,
                        width: 200
                    }, {
                        field: 'useridget',
                        title: '接收者推广号',
                        height: 300,
                        width: 150
                    }, {
                        field: 'nicknameget',
                        title: '接收者昵称',
                        height: 300,
                        width: 200
                    }, {
                        field: 'giftName',
                        title: '礼物名称',
                        height: 100,
                        width: 200
                    }, {
                        field: 'amount',
                        title: '总金币',
                        height: 300,
                        width: 200
                    }, {
                        field: 'timegive',
                        title: '赠送时间',
                        height: 300,
                        width: 200
                    }, {
                        field: 'timeget',
                        title: '领取时间',
                        height: 300,
                        width: 250
                    }, {
                        field: 'operation',
                        title: '操作',
                        height: 300,
                        width: '100',
                        toolbar: '#stateTpl'
                    }
                ]
            ],
            skin: 'row', //表格风格
            even: true,
            page: true,
            limits: [30, 50, 100],
            limit: 100, //每页默认显示的数量
            width: 'full-10',
            rules: 'all',
            height: 'full-105'
        });
    }

function ShowUserDatas()
{
    var dUserGameID =  document.getElementById("userID");
    dUserGameID.value=localStorage["gameid"];            
          
}

</script>
</body>

</html>